package cn.itrip.service.impl;

import cn.itrip.entity.ItripLabelDic;
import cn.itrip.dao.ItripLabelDicDao;
import cn.itrip.service.ItripLabelDicService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 标签字典表(ItripLabelDic)表服务实现类
 *
 * @author makejava
 * @since 2022-04-14 22:34:58
 */
@Service("itripLabelDicService")
public class ItripLabelDicServiceImpl implements ItripLabelDicService {
	@Resource
	private ItripLabelDicDao itripLabelDicDao;

	/**
	 * 通过ID查询单条数据
	 *
	 * @param id 主键
	 * @return 实例对象
	 */
	@Override
	public ItripLabelDic queryById(Long id) {
		return this.itripLabelDicDao.queryById(id);
	}

	/**
	 * 分页查询
	 *
	 * @param itripLabelDic 筛选条件
	 * @param pageRequest   分页对象
	 * @return 查询结果
	 */
	@Override
	public Page<ItripLabelDic> queryByPage(ItripLabelDic itripLabelDic, PageRequest pageRequest) {
		long total = this.itripLabelDicDao.count(itripLabelDic);
		return new PageImpl<>(this.itripLabelDicDao.queryAllByLimit(itripLabelDic, pageRequest), pageRequest, total);
	}

	/**
	 * 新增数据
	 *
	 * @param itripLabelDic 实例对象
	 * @return 实例对象
	 */
	@Override
	public ItripLabelDic insert(ItripLabelDic itripLabelDic) {
		this.itripLabelDicDao.insert(itripLabelDic);
		return itripLabelDic;
	}

	/**
	 * 修改数据
	 *
	 * @param itripLabelDic 实例对象
	 * @return 实例对象
	 */
	@Override
	public ItripLabelDic update(ItripLabelDic itripLabelDic) {
		this.itripLabelDicDao.update(itripLabelDic);
		return this.queryById(itripLabelDic.getId());
	}

	/**
	 * 通过主键删除数据
	 *
	 * @param id 主键
	 * @return 是否成功
	 */
	@Override
	public boolean deleteById(Long id) {
		return this.itripLabelDicDao.deleteById(id) > 0;
	}
}
